package com.zck.thumbup.controller;


import com.zck.thumbup.common.BaseResponse;
import com.zck.thumbup.common.ResultUtils;
import com.zck.thumbup.entity.Blog;
import com.zck.thumbup.model.BlogVO;
import com.zck.thumbup.service.BlogService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhaochenkang
 * @since 2025-10-16
 */
@RestController
@RequestMapping("/blog")
public class BlogController {

    @Resource
    private BlogService blogService;

    @GetMapping("/get")
    public BaseResponse<BlogVO> get(long blogId, HttpServletRequest request){
        BlogVO blogVO = blogService.getBlogVOById(blogId, request);
        return ResultUtils.success(blogVO);
    }

    @GetMapping("/list")
    public BaseResponse<List<BlogVO>> list(HttpServletRequest request){
        List<Blog> blogList = blogService.list();
        List<BlogVO> blogVOList = blogService.getBlogVOList(blogList, request);
        return ResultUtils.success(blogVOList);
    }

    @PostMapping("/save")
    public BaseResponse<String> saveBlog(Blog blog,HttpServletRequest request){
        Boolean success = blogService.saveBlog(blog, request);
        if (success) {
            return ResultUtils.success("添加成功!");
        }else {
            return ResultUtils.success("添加失败!");
        }
    }


}
